<template>
  <a-row type="flex" style="flex-flow: inherit;">
    <a-col :flex="toggle ? '260px' : '30px'" style="margin-right: 12px;background-color: #fff;">
      <depart-tree :rootOpened="true" :multi="false" @ok="getTreeData" @toggleBool="toggleBool" />
      <!-- <groups-tree @tree="getTreeData" @selectedKeys="getSelectedKeys" /> -->
    </a-col>
    <a-col flex="auto">
      <a-card :bordered="false" style="margin-bottom: 10px">
        <!-- 查询区域 -->
        <div class="table-page-search-wrapper" style="position: relative">
          <div class="search-wrapper-btn">
            <a-button type="link" @click="show = !show">
              <span v-if="!show">展开
                <a-icon type="down" />
              </span>
              <span v-else>收起
                <a-icon type="up" />
              </span>
            </a-button>
          </div>
          <a-form-model :label-col="labelCol" :wrapper-col="wrapperCol" @keyup.enter.native="onQuery">
            <div class="mode_item">
              <div class="mode_item_div">
                <a-form-model-item label="人员姓名">
                  <a-input v-model="form.sjskPersonName"></a-input>
                </a-form-model-item>
              </div>
              <div class="mode_item_div">
                <a-form-model-item label="人员类型">
                  <a-select v-model="form.sjskType" placeholder="请选择">
                    <a-select-option value="1">
                      社区戒毒
                    </a-select-option>
                    <a-select-option value="2">
                      社区康复
                    </a-select-option>
                  </a-select>
                </a-form-model-item>
              </div>
              <div class="mode_item_div">
                <a-form-model-item label="身份证号">
                  <a-input v-model="form.identityCard"></a-input>
                </a-form-model-item>
              </div>
            </div>
            <div class="mode_item" v-show="show">
              <div class="mode_item_div mode_item_flex">
                <a-form-model-item label="状态">
                  <a-radio-group v-model="form.status" @change="onStatusChange">
                    <a-radio value="">全部</a-radio>
                    <a-radio :value="2">待录入</a-radio>
                    <a-radio :value="6">已完成</a-radio>
                  </a-radio-group>
                </a-form-model-item>
              </div>
            </div>
            <div class="btnBox">
              <a-form-model-item :wrapper-col="{ offset: 0 }" style="margin-bottom: 0">
                <a-button type="primary" @click="onQuery"> 查询 </a-button>
                <a-button style="margin-left: 10px" @click="onResetForm"> 重置 </a-button>
              </a-form-model-item>
            </div>
          </a-form-model>
        </div>
      </a-card>
      <a-card :bordered="false">
        <!-- 操作按钮区域 -->
        <div class="table-operator">
          <a-button  @click="exportList()">导出</a-button>
        </div>
        <!-- 表格展示 -->
        <div class="table-page-content">
          <z-table ref="table" rowKey="id" :showAlert="false" :showSelection="true" :loading="loading"
            :columns="columns" :dataSource="pageData" @selectedRow="onSelectedRow" @change="onTableChange">
            <!--操作-->
            <template slot="action" slot-scope="text, record">
              <a-button @click="onInput(record)" type="link" style="padding: 0" :disabled="record.status == 6">添加预估</a-button>
              <a-divider type="vertical" />
              <a-button @click="onSubmitIdea(record)" type="link" style="padding: 0" :disabled="Boolean(record.supervisorOpinion)">提交意见</a-button>
              <a-divider type="vertical" />
              <a-button @click="onDetail(record)" type="link" style="padding: 0">查看</a-button>
              <a-divider type="vertical" />
            </template>
          </z-table>
        </div>
        
        <DetailModal ref="detailModalId" />
        <IdeaModal ref="IdeaModal" jTitle="提交意见"/>
      </a-card>
    </a-col>
  </a-row>
</template>

<script>
import moment from 'moment'
// import * as peopleApi from '@/api/wxSmuggle/people.js'

import DetailModal from './modules/DetailModal'
import DepartTree from '@/views/sjsk/modules/departTree'
import IdeaModal from './modules/IdeaModel.vue'


import { estimateList, estimateListExport } from '@/api/sjsk/estimate/list/index'
import { downLoadFileReader } from '@/utils/export-util/util'

export default {
  props: {
    form: {
      type: Object,
      default: () => {
        return {
          
        }
      }
    }
  },
  components: {
    
    DepartTree,
    DetailModal,
    IdeaModal
  },
  data() {
    return {
      moment,
      labelCol: { span: 6 },
      wrapperCol: { span: 16 },
      rangePickerTime: [],
      show: false,
      loading: false,
      visible: false,
      isDisabled: true,
      reloading: false,
      selectKeys: [],
      form: {},
      timeValue: undefined,
      statusValue: undefined,
      treeDatas: [],
      toggle: true,
      columns: [
        {
          title: '序号',
          dataIndex: 'order',
          width: 60,
          align: 'center',
          customRender: (text, record, index) =>
            `${(this.pageFilter.pageNo - 1) * this.pageFilter.pageSize + (index + 1)}` //序号分页后连续
        },
        {
          title: '姓名',
          dataIndex: 'realName',
          align: 'center',
          customRender: (text) => {
            return <j-ellipsis value={text} length={20} />
          },
        },
        {
          title: '身份证',
          dataIndex: 'identityCard',
          align: 'center',
          customRender: (text) => {
            return <j-ellipsis value={text} length={20} />
          },
        },
        {
          title: '人员类型',
          dataIndex: 'sjskType',
          align: 'center',
          customRender: (text) => {
            return <j-ellipsis value={text == 1 ? '社区戒毒' : '社区康复'} length={14} />
          },
        },
        {
          title: '联系电话',
          dataIndex: 'phone',
          align: 'center',
        },
        {
          title: '状态',
          dataIndex: 'status',
          align: 'center',
          customRender: (text) => {
            
            return <j-ellipsis value={text == 2 ? '待录入' : '已完成'} length={14} />
          },
        },
        {
          title: '添加时间',
          dataIndex: 'createTime',
          align: 'center',
        },
        {
          title: '操作',
          width: 250,
          align: 'center',
          dataIndex: 'action',
          scopedSlots: { customRender: 'action' },
        },
      ],
      pageFilter: {
        pageNo: 1,
        pageSize: 10,
      },
      pageData: {
        records: []
      },
      jTitle: "添加季度评估",
    }
  },
  created() {

  },
  async mounted() {
    // this.onQuery()
  },

  methods: {
    exportList() {
      const params = Object.assign(this.form, this.pageFilter)
      estimateListExport(params).then(async res => {
        const fileName = '预估列表.xls'
        await downLoadFileReader(res, fileName)
      })
    },
    onSubmitIdea(record) {
      this.$refs.IdeaModal.show(record)
    },
    
    
    onQuery() {
      this.pageFilter.pageNo = 1
      this.refreshTable()
    },
    onResetForm() {
      this.form = {}
      this.pageFilter.pageNo = 1
      this.pageFilter.pageSize = 10
      this.refreshTable()
    },
    onTimeChange() {

    },
    onStatusChange() {

    },
    onSelectedRow(keys) {
      this.selectKeys = keys
      this.isDisabled = keys.length > 0 ? false : true
    },
    onTableChange(pagination, pageFilter, sorter) {
      let keyMap = { currentPage: 'pageNo' }
      let paginations = Object.keys(pagination).reduce((newData, key) => {
        let newKey = keyMap[key] || key
        newData[newKey] = pagination[key]
        return newData
      }, {})
      this.pageFilter = Object.assign({}, this.pageFilter, paginations)
      this.refreshTable()
    },
    refreshTable() {
      let form = Object.assign({}, this.form, this.pageFilter)
      this.loading = true
      estimateList(form)
        .then((res) => {
          if (res.success) {
            this.pageData = res.result ? res.result : {}
            this.loading = false
            this.$refs.table.onClearRowKeys()
          } else {
            this.loading = false
          }
        })
        .catch((e) => {
          this.loading = false
          this.$message.warn('请求失败！')
        })
    },
    getSelectedKeys(keys) {
      console.log(keys)
      this.$set(this.form, 'labelId', keys.join(','))
      this.onQuery()
    },
    onBooking() {
      this.$refs.scheduleModalId.show()
    },
    onInput(record) {
      let url = '/estimate/form?'
      for (let key in record) {
        url += `${key}=${record[key]}&`
      }
      this.$router.push(url)
      console.log(url)
    },
    onHistory(record) {
      this.$router.push({
        path: "/estimate/record",
        query: {
          id: record.id
        }
      })
    },
    onDetail(record) {
      this.$router.push(`/estimate/detail?sjskPersonId=${record.sjskPersonId}&personType=${record.personType}`)
    },
    onCYX(record) {

    },
    onCX() {
      let that = this;
      this.$confirm({
        title: `还在审批中，确定要撤销吗?`,
        okText: "确认",
        okType: "danger",
        cancelText: "取消",
        onOk() {
          // api.deleteTemplate({ id: arr }).then(() => {
          //   that.$message.success("删除成功");
          //   that.getTemplateList();
          // });
        }
      });
    },
    // 修改分组
    handleProups() {
      let selectList = this.$refs.table.getSelectedRows()
      let idList = selectList.map((v) => v.id).filter((obj) => obj !== null && obj !== undefined && obj !== '')
      this.$refs.groupsModalRef.edit(idList)
    },
    /** 重新加载组件 */
    reload() {
      this.reloading = true
      this.$nextTick(() => (this.reloading = false))
    },
    getTreeData(datas, id) {
      console.log(datas)
      console.log(datas[0].id)
      this.form.departmentId = id
      this.onQuery()
    },
    toggleBool(bool) {
      console.log(bool)
      this.toggle = bool
    }
  },
}
</script>
<style lang="less" scoped>
.mode_item {
  display: flex;
  border-bottom: 1px #dadada dashed;

  .mode_item_div {
    width: 26%;
    padding: 5px 0;

    .ant-form-item {
      margin-bottom: 0;
    }
  }

  &>* {
    width: 100%;
    margin-bottom: 0;
    padding: 10px 0;
  }
}

.mode_item_flex {
  width: 70% !important;

  /deep/ .ant-col-6 {
    width: 9.5% !important;
  }
}

.search-wrapper-btn {
  position: absolute;
  right: 15%;
  top: 9px;
  z-index: 100;
}

.btnBox {
  position: absolute;
  right: 0;
  top: 5px;
  z-index: 120;
}

@import '~@assets/less/common.less';
</style>
